package exlog

import (
	"github.com/spf13/viper"
	"log"
	"os"
	"strconv"
	"time"
)

var (
	err         error
	LOGPATH     string
	logFilePath string
	Y           string
	M           string
	D           string
	logFile     *os.File
)

//日志目录以及flag设置
func InitLog() {
	LOGPATH = viper.GetString("LOGPATH")
	Y = strconv.Itoa(time.Now().Year())
	M = strconv.Itoa(int(time.Now().Month()))
	D = strconv.Itoa(int(time.Now().Day()))
	logFilePath = LOGPATH + "log_" + Y + "-" + M + "-" + D + ".log"
	logFile, err = os.OpenFile(logFilePath, os.O_RDWR|os.O_CREATE|os.O_APPEND, 0766)
	if err != nil {
		panic("日志文件未打开")
	}
	// 将文件设置为log输出的文件
	log.SetOutput(logFile)
	log.SetFlags(log.LstdFlags | log.Lshortfile | log.LUTC)
}
